import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;

//首先这道题处理输入重要注意
//整体思路研究后还是可以看懂 加油
public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int num = sc.nextInt();
            Person[] arr = new Person[num];
            //输入每个人体重身高非常巧妙，新建了Person类
            for(int i = 0; i < num; i++){
                int index = sc.nextInt();
                arr[index-1] = new Person(sc.nextInt(),sc.nextInt());
            }
            //实现Comparator接口
            Arrays.sort(arr, new Comparator<Person>() { //由于Person类本身没有实现内部比较器Comparable接口，所以需要传入一个外部比较器Comparator
                public int compare(Person p1, Person p2) {
                    int res1 = Integer.compare(p1.height, p2.height);  //取得按身高排序的结果
                    if (res1 != 0) {
                        return res1;
                    } else {   //身高相同的情况下，按体重升序排序
                        return Integer.compare(p1.weight, p2.weight);
                    }
                }
            });
            int[] F = new int[num];
            F[0] = 1;
            int max = 0;
            for(int i = 1; i < num; i++){
                F[i] = 1;
                for (int j = i - 1; j >= 0; j--) {
                    if (arr[i].weight > arr[j].weight || (arr[i].weight == arr[j].weight && arr[i].height == arr[j].height)) {
                        F[i] = Math.max(F[i], F[j] + 1);
                    }
                }
                max = Math.max(max, F[i]);
            }
            System.out.println(max);
        }
        sc.close();
    }
}

class Person{
    int weight;
    int height;
        
    public Person(int weight, int height){
        this.weight = weight;
        this.height = height;
    }
}